<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
  <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
  <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
  <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
</head>
<body>
  <div class="container" id="vuebox">
    <form>
      <label for="oldpassord">原始密码:</label>
      <input type="password" v-model="oldpassord" id="oldpassord">
      <br/>
      <label for="newpassord">新密码:</label>
      <input type="password" v-model="newpassord" id="newpassord">
      <br/>
      <label for="confirmpassord">确认密码:</label>
      <input type="password" v-model="confirmpassord" id="confirmpassord">
      <br/>
      <button type="button" @click="upUsers">修改</button>
      <button type="button">返回</button>
    </form>
  </div>
</body>
</html>
<script type="text/javascript">
        var vm=new Vue({
            el:"#vuebox",
            data:{
                confirmpassord:"",
                newpassord:"",
                oldpassord:"",
                result:"",
                upreuslt:"",
                oldreuslt:""
            },
            methods:{
                upUsers:function () {
                    if(this.oldpassord.length==0 || this.newpassord.length==0 || this.confirmpassord.length==0){
                    alert("各项不能为空!")
                        return;
                    }
                    if(this.confirmpassord!=this.newpassord){
                        alert("新旧密码输入不一致")
                       return;
                    }
                    if(this.oldpassord.length<5|| this.newpassord.length<5 || this.confirmpassord.length<5){
                        alert("密码长度不能小于5")
                        return;
                    }
                    axios.get("/seleusersByPassword",{params:{password:this.oldpassord}}).then(res=>{
                        this.result=res.data;
                        if(this.result=="fail"){
                            this.oldreuslt="error";
                        }
                    })
                    if(this.oldreuslt.length!=0){
                        alert("你的旧密码输入错误!")
                        return;
                    }
                    axios.get("/doup",{params:{password:this.newpassord}}).then(res=>{
                        this.upreuslt=res.data;
                        if(this.upreuslt=="SUCCESS"){
                            alert("修改密码成功,请重新登录!")
                            window.location.href="http://localhost:8081/tologin";
                        }else{
                            alert("修改失败!")
                        }
                    })
                }
            }
    })
</script>